<template>
  <view class="content">
    <view class="box">
      <view class="icon-1">
        <image :src="image_host+'img_zhucechenggong.png'"></image>
      </view>
      <view class="title">
        <view v-if="!title">恭喜您注册成功!<br/>
          请确认绑定微信
        </view>
        <text v-else>{{ title }}</text>
      </view>
      <view class="icon-2">
        <image :src="image_host+'icon_bangding_weixin.png'"></image>
      </view>
      <button v-if="isButton" class="button" open-type="launchApp" app-parameter="wechat" binderror="launchAppError">
        确定
      </button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      image_host: this.image_host + 'login/',
      isButton: false,
      title: ""
    };
  },
  onShow() {
    wx.hideHomeButton();
    this.login()
  },
  methods: {
    launchAppError(e) {
      console.log(e.detail.errMsg)
    },
    login() {
      let _this = this
      uni.login({
        provider: 'weixin',
        success: function (loginRes) {
          _this.check_login(loginRes.code);
        }
      })
    },
    async check_login(code) {
      let data = {code: code}
      let res = await this.$NoteApi.doRequest("get", "login", data, '', true);
      if (res.data.code !== 0) {
        uni.showModal({title: '错误', content: res.data.message})
        this.title = res.data.message
        return
      }
      this.isButton = true
    }
  }
}
</script>

<style lang="scss">
.content {
  width: 100%;
  height: 100vh;
  overflow: auto;
  padding: 0 24upx;
  box-sizing: border-box;
}

.box {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.icon-1 image, .icon-2 image {
  width: 100%;
  height: 100%;
}

.icon-1 {
  width: 300upx;
  height: 300upx;
}

.title {
  width: 100%;
  text-align: center;
  font-size: 70upx;
  color: #333333;
  line-height: 80upx;
  margin-top: 10upx;
}

.icon-2 {
  width: 420upx;
  height: 223upx;
  margin-top: 36upx;
}

.button {
  width: 600upx;
  height: 98upx;
  font-size: 44upx;
  background-color: #18AA59;
  border-radius: 45upx;
  line-height: 98upx;
  text-align: center;
  color: #FFFFFF;
  margin-top: 101upx;
}
</style>
